<?php
namespace app\index\controller;

use library\Controller;
use app\admin\service\NodeService;
use think\Db;

class User extends Base
{


    public function changepw()
    {
    	if($this->request->isPost()){
    		$data = $this->request->post();
			trim_array($data);
			$member = Db::name('system_member')->where(['id'=>$this->company['mid']])->find();
			if($member['password'] != md5($data['orpassword'])){
				$this->error('原密码错误');
			}
			if($data['password'] != $data['repassword']){
				$this->error('两次密码不一致');
			}
			$result = NodeService::checkpwd($data['password']);
            if (empty($result['code'])) $this->error($result['msg']);
			$re = Db::name('system_member')->where(['id'=>$this->company['mid']])->update(['password'=>md5($data['password'])]);
			if($re){
				\think\facade\Session::clear();
        		\think\facade\Session::destroy();
				$this->success('密码修改成功，请重新登录', url('index/login/index'));				
			}else{
				$this->error('修改失败，请稍后再试');
			}
    	}
        $this->fetch();
    }
}